<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Talk;

class TalkController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        $talk = Talk::orderBy('created_at','DESC')->paginate(5);
        
        return view('admin.talkAdmin',compact('talk'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  Request  $request
     * @return Response
     */
    public function store(Request $request)
    {
        Talk::create($request->except('_token'));
        
        return redirect(url('yhsystem/talk'))->withSuccess('发布成功');        
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  Request  $request
     * @param  int  $id
     * @return Response
     */
    public function update(Request $request, $id)
    {
        $talk = Talk::findOrFail($id);
        
        $talk->update($request->except(['_token']));

        return redirect(url('yhsystem/talk'))->withSuccess('发布成功'); 
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
        Talk::destroy($id);
        return redirect(url('yhsystem/talk'))->withSuccess('删除成功'); 
    }

}
